Page Index
9 A Swagger文档配置
JL 于 2022-01-06 16:53:41 +08:00 修改了此页面
此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

快速使用

在pom.xml中引入

    <dependency>
        <groupId>com.joolun</groupId>
        <artifactId>base-common-swagger</artifactId>
    </dependency>

启动类中增加@BaseEnableSwagger注解

@BaseEnableSwagger
@SpringCloudApplication
@EnableBaseFeignClients
@EnableBaseResourceServer
public class BaseWeiXinApplication {

	public static void main(String[] args) {
		SpringApplication.run(BaseWeiXinApplication.class, args);
	}
}

个性化的配置application-dev.yml

# Swagger相关的配置
swagger:
  # 标题,默认空
  title: 'JooLun Swagger API'
  # 描述,默认空
  description: 'JooLun微信快速开发框架'
  # 版本,默认空
  version: '2.1.6'
  # 许可证,默认空
  license: 'Powered By JooLun'
  # 许可证URL,默认空
  licenseUrl: 'http://www.joolun.com'
  # 服务条款URL,默认空
  terms-of-service-url: 'http://www.joolun.com'
  # 文档的host信息,默认空
  host: 'http://www.joolun.com'
  # swagger会解析的包路径,默认为空,扫描所有包
  base-package: '' 
  # swagger会解析的url规则
  base-path: /**
  # 在basePath基础上需要排除的url规则
  exclude-path: 
    - /actuator/**
    - /error  
  # 联系人相关配置
  contact:
    # 联系人姓名,默认空
    name: 'JL'
    # 联系人Email,默认空
    email: 'joolun@gmail.com'
    # 联系人URL,默认空
    url: 'http://www.joolun.com'
  # 统一鉴权相关配置
  authorization:
    # 鉴权策略名称,默认空
    name: 'JooLun OAuth'
    # 需要开启鉴权URL的正则,默认匹配所有
    auth-regex: '^.*$'
    # 鉴权作用域列表配置,默认空
    authorization-scope-list:
        # 鉴权作用域名称,默认空
      - scope: 'server'
        # 鉴权作用域描述,默认空
        description: 'server all'
    # 校验token的地址列表,默认空  
    token-url-list:
      - 'http://localhost:9999/auth/oauth/token'

文档地址: http://base-gateway:9999/doc.html http://base-gateway:9999/swagger-ui.html 参考:https://doc.xiaominfo.com/guide/

文档查看及调试

  • 后台查看接口文档

  • 接口调试,由于前后端都有验权校验,需使用postman工具
  1. 后台管理端接口调试:https://git.joolun.com/joolun-mp-ma/mp-ma/wiki/A-%E5%A6%82%E4%BD%95%E6%96%B0%E5%BB%BA%E5%BE%AE%E6%9C%8D%E5%8A%A1%EF%BC%8C%E5%B9%B6%E7%94%A8postman%E6%8E%A5%E5%8F%A3%E8%B0%83%E8%AF%95
  2. 小程序前端接口调试:https://git.joolun.com/joolun-mp-ma/mp-ma/wiki/C-%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%8E%A5%E5%8F%A3%E8%AE%BF%E9%97%AE%E5%8E%9F%E7%90%86%E3%80%81postman%E8%B0%83%E8%AF%95%E3%80%90%E6%96%B0%E3%80%91